import java.util.Arrays;

/**
 * 可重複排列問題
 * @author Raymond Wu (小璋丸)
 */
public class Permulate {

	public static void perm(int[] data) {
		int i;
		int li,ri,temp;
		
		for(i=0;i<data.length;i++) System.out.print(data[i]+" ");
		System.out.println();

		ri = data.length-1;
		while(ri>0) {			
			for(li=ri-1;li>=0;li--) {
				if(data[li]<data[ri]) {
					temp = data[li];
					data[li] = data[ri];
					data[ri] = temp;
					ri = data.length-1;
					if(li<data.length-2) Arrays.sort(data,li+1,data.length);
					for(i=0;i<data.length;i++) System.out.print(data[i]+" ");
					System.out.println();
					break;
				}
			}
			if(li==-1) ri--;
		}
	}
	
	public static void main(String[] args) {
		int[] data1 = {1,1,2,3};
		perm(data1);
	}

}
